package worktest;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class TestList {

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		List<String> list = new ArrayList<String>();
		list.add("a");
		list.add("b");
		list.add("c");
		List<String> list2 = deepcopy(list);
		System.out.println(list);
		System.out.println(list2);
		System.out.println("=================");
		list.clear();
		System.out.println(list);
		System.out.println(list2);
	}
	
    public static List deepcopy(List src) throws IOException,ClassNotFoundException {
			ByteArrayOutputStream byteout = new ByteArrayOutputStream();
			ObjectOutputStream out = new ObjectOutputStream(byteout);
			out.writeObject(src);
			ByteArrayInputStream bytein = new ByteArrayInputStream(byteout
					.toByteArray());
			ObjectInputStream in = new ObjectInputStream(bytein);
			List dest = (List) in.readObject();
			return dest;

    }

}
